Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Plot innovation variance and covariance parameters*

    I run two types of models: a rolling VAR and a rolling PVAR, and I need to run both.

    1)
    ​collect the observation error covariance parameters and plot the credible intervals

    And

    2) Collect the (state) innovation variance parameters ​​​​and plot the credible intervals.

    How do I do that?

    Data sample for the standard VAR are given below The code I run are:

    Code:
     tsset year 
    quietly rolling, window(12) clear : var mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1)
    and :

    Code:
    quietly rolling, window(12) clear : pvar mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1)
    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(year mag0 mag1 car0 car1 ka vehicle col0 col1 re fd)
    1945 .08333334 .9166667        1           0           .            .            .             .             .             .
    1946 .11104685 .8889531 .9972528  .002747253           .     .0767169   .007133216   -.007133186             .             .
    1947 .19947444 .8005255 .9980889 .0019111324           .  -.033678144    .05756658    -.05756658             .             .
    1948 .22086407 .7406744 .9615384           0           .    .02165809  -.034264237  -.0041972995             .             .
    1949  .1937322 .7993488  .993081           0           .  -.003348023   .000801742      .0307408             .             .
    1950  .2035002 .7964998  .992267  .007733008           .  .0028122663  -.030423284     .03734231             .             .
    1951 .22954823 .7704518 .9502442    .0497558           .  -.003260791    .05352053    -.05352056             .             .
    1952 .16732623 .8326738 .9955353 .0044647385           .   .033309698    -.0533452      .0533452             .             .
    1953 .16870166 .8312984 .9815832  .018416768           .  -.008517623    .08407372    -.08407375             .             .
    1954 .17623118 .8237689 .9855515  .014448515           .  -.008653492  -.013736248    .013736278             .             .
    1955  .1921042 .8078958 .9871795  .012820513           .   .005571097    -.0450753      .0450753             .             .
    1956 .18711314 .8128868 .9950279  .004972095           .  -.013731807  -.008823812    .008823812             .             .
    1957  .1980057 .7987383  .996744           0           .   .006495297     .0465731    -.04982913             .             .
    1958 .17531542 .8002645 .9734432 .0021367522           .  .0042423904    .03551078    -.05667481             .             .
    1959  .3041311  .695869 .9708995   .02910053           . -.0012779236    .09544164    -.07102156             .             .
    1960 .26169458 .7383054        1           0           .  -.015391976   -.03749508     .03749505             .             .
    1961 .27614978 .7238503 .9675417  .032458283           .    .00309664    .03749508    -.03749505             .             .
    1962 .27188328 .7281167 .9976317 .0023683214           .   .010390967   -.11199883     .11199877             .             .
    1963  .3119553 .6880447  .969496   .03050398           .   -.01049766  -.001894653    .001894653             .             .
    1964  .3092237 .6907762 .9722375   .02776256           .   .004954934   .015789598   -.015789539             .             .
    1965  .2330586 .7669414        1           0           .     .0115287   -.05335116     .05335113             .             .
    1966 .17653315 .8234668 .9927331  .007266927           .   .012013525    .02140197      -.021402             .             .
    1967 .22536334 .7746366 .9595888    .0404112           .  -.011647135    .04271534    -.04271531             .             .
    1968  .1899249 .8100751 .9677419  .032258064           .    .01712513  -.018935263    .018935263             .             .
    1969 .19505495 .8049451 .9677419  .032258064           .  -.014389515  -.007119328    .007119298             .             .
    1970  .2045374 .7899681 .9622474  .032258064           .  .0019976795   .025434285    -.03092873             .             .
    1971  .2260723 .7739277 .9621588   .03784119  -.39362165  -.021190494   .006380677  -.0008862019             .             .
    1972 .27264693 .7169244 .9406098   .04896155  -.24231456  -.007597685    .05811477   -.068543434             .             .
    1973 .21797733 .7507727 .9263393   .04241072  -.24066724   .006259322  -.021107137  .00028583407             .             .
    1974 .20072116 .7578125 .9370707   .02146291   -.2665547   .005590796    .02026099   -.030477345             .             .
    1975 .17659684 .8094093 .9783654  .007640797  -.24634326   .006330937    .01244849    .015024036             .             .
    1976   .184973  .815027 .9853051  .014694895  -.31063345    .01055935 -.0037447214    .017738491             .             .
    1977 .23524334 .7647567 .9867347  .013265306   -.4182096 -.0006091893    .05594742    -.05594736             .             .
    1978 .21381475 .7764521 .9846154  .005651491   -.3896763 -.0009466112  -.018916786    .009183645             .             .
    1979 .28434065 .6985294 .9394796   .04339043   -.3896763    .01392892  .0014082193   -.008805037             .             .
    1980  .1752619 .8247381 .9987913 .0012087027  -.29550555   -.02210301    .01566708   .0014628172             .             .
    1981  .2135585 .7864415 .9974144   .00258565  -.34505615  -.010849535  -.015343845    .015343904             .             .
    1982  .3413058 .6586943 .9786684   .02133161  -.25163704   .004226178    .02456367    -.02456367   .0001324024    .006160483
    1983 .26389787 .7361021 .9928895  .007110537   -.1750894   -.00328362   -.06221724     .06221718   -.014355402    .014019087
    1984 .18436745 .8156326        1           0  -.10805306  .0010181367   -.05473828     .05473831   -.007924562    .014482632
    1985  .1516645 .8483355        1           0  -.08923411 -.0006535053    .02088243    -.02088246    .005102764    .009850457
    1986 .19957983 .8004202        1           0   -.0594031  .0020222664   .034017503   -.034017444   -.010541415     .02026184
    1987 .23287007   .76713 .9941823  .005817712  -.14884342   .006771833     .0583387    -.05833873     .01484855     .01551783
    1988 .22385173 .7761483 .9896051  .010394843   -.1206697  -.003155172    .01464212    -.01464212     .01575236      .0220432
    1989 .23149644 .7685035 .9966871 .0033128636 -.036256615   .016436338   -.05698216     .05698213 -.00008889288  -.0046534836
    1990 .27984852 .7201515  .994654  .005346005 .0005995822    .05697283  -.015793383    .015793443   -.018172212     .02081114
    1991  .3284199 .6465201 .9749401           0   .07461239     43.27272    .02895367    -.05401364    .015567867    .008893073
    1992  .3083437  .691594 .9999377           0   .12935932    .04439545   -.09506172      .1200594   -.018236343 -.00018396974
    1993 .24354993 .7332776 .9604037  .016423794    .3613803    -1.770897   -.04099771    .017887473   -.005394331    .013688922
    1994 .23602992 .7400631 .9677929   .00830021    .6830521     .0444107   -.09033784      .0896034    .010098682    .033943623
    1995 .27747253 .7225274 .9669732  .033026755    .7524721   .022476196    .04459012    -.02068317      .0101888     .01792264
    1996   .325723  .674277 .9697465  .030253503     .857617    .02706146   -.05218634     .05218637     .01386066   .0020535886
    1997 .30558395 .6757603 .9518272  .029516995    .7424365    .01917267  -.036713243    .018057466   -.024909677     .01871976
    1998 .29313186 .6818681 .9739011 .0010989011    .7895167    .01044464   -.04234445    .036000192     .00673125     .03958488
    1999 .28042582 .7138736 .9756181   .01868132    .8327662   .000793457    .02678573   -.007486284    .008219708      .0237163
    2000  .2688356 .7311644 .9853424  .014657534    .9176872   .029144287  -.016068995    .021769524    -.02601591   .0046441555
    2001  .2554258 .7445742 .9921017  .007898351    .9703661   .031337738   .012772292   -.012772262    .007965174     .02297038
    2002  .2105769  .789423  .982967  .017032966   1.0378017   .015750885   -.07252747     .07252747    .005473087   -.006904125
    2003  .1955357 .8044643  .985989   .01401099   1.1644768   .016868591 .00020602345 -.00020605326    .018079296   -.007299632
    2004  .2408904 .7591096        1           0    1.276395     .0190773   .012151897   -.012151897    .022712436     .01002726
    2005  .2480769 .7519231        1           0   1.3937308    .01517105 -.0023991466   .0023991466   -.022985077    .015026867
    2006  .2673077 .7326923 .9806319   .01936813    1.459883    .02935791   .030700564   -.030700505  -.0082911225    .011752129
    2007 .26824456 .7317554 .9940829   .00591716   1.5610563   .024166107   -.03289485     .03289479     -.0102654    .023671627
    2008  .2303533 .7696467        1           0   1.5881433    .02479172  -.013935775    .013935804    .019328535     .02137667
    2009 .23055235 .7694477 .9828658  .017134182   1.5653305    .02153778    .06577581    -.06577581   -.010148779   -.015480518
    2010 .29588655 .7041135 .9681467   .03185328   1.5544957   .015098572   -.02413714     .02413714   -.018703487      .0095371
    2011  .3009355 .6958717 .9968072           0   1.5382434    .00982666   -.06095931     .05776656      .0073763   -.004389167
    2012 .25005552 .7229174 .9703073 .0026656794    1.521991   .029712677  -.021239385   -.002594888     .01201999   -.008769155
    2013 .20782596 .7834868  .972676   .01863677   1.4883434   .017562866  -.007940888     .02628064    -.02810171   -.009512424
    2014 .22527473 .7747253 .9808435   .01915652   1.4627517    .02828598  -.028363526    .037050784    .018062308   -.000639975
    2015         .        .        .           .    1.490982   .018558502            .             .   -.003878433  -.0006780028
    2016         .        .        .           .    1.501817    2.8140755            .             .   -.029535156     .00385046
    2017         .        .        .           .   1.5382434    -44.66236            .             .     .04417016  -.0021682382
    2018         .        .        .           .   1.5207077            .            .             .    .002493127    .007712066
    2019         .        .        .           .    1.483138            .            .             .   -.007930711   -.005730808
    2020         .        .        .           .           .            .            .             .    -.01844586             .
    end

  • #2
    I don't know about var and pvar, so I cannot help you with that. But I suspect that the problem is that rolling overwrites the data, so once you have run quietly rolling, window(12) clear : var mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1) you no longer have the data in memory and quietly rolling, window(12) clear : pvar mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1) won't run. Even if you get you command to run by opening the data again, you loose the result from the first command.

    This sounds like a case for frames. Here is a sketch of what that would look like:

    Code:
    // have the data in a frame called data
    frames reset
    frame create data
    frame change data
    use data.dta // open the data, it is probably not called data.dta but you get the point
    tsset year
    
    // copy the data to a frame called var
    frame copy data var, replace
    frame change var
    quietly rolling, window(12) clear : var mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1)
    
    //copy the data to a frame called pvar
    frame copy data pvar, replace
    frame change pvar
    quietly rolling, window(12) clear : pvar mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1)
    
    // collect the variable(s) you need from the frame var into frame pvar
    frlink 1:1 start , frame(var)
    frget your_variable_of_choice, from(var)
    
    // now you can create the graph with both parameters
    Last edited by Maarten Buis; 31 May 2023, 01:54.
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Originally posted by Maarten Buis View Post
      I don't know about var and pvar, so I cannot help you with that. But I suspect that the problem is that rolling overwrites the data, so once you have run quietly rolling, window(12) clear : var mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1) you no longer have the data in memory and quietly rolling, window(12) clear : pvar mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1) won't run. Even if you get you command to run by opening the data again, you loose the result from the first command.

      This sounds like a case for frames. Here is a sketch of what that would look like:

      Code:
      // have the data in a frame called data
      frames reset
      frame create data
      frame change data
      use data.dta // open the data, it is probably not called data.dta but you get the point
      tsset year
      
      // copy the data to a frame called var
      frame copy data var, replace
      frame change var
      quietly rolling, window(12) clear : var mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1)
      
      //copy the data to a frame called pvar
      frame copy data pvar, replace
      frame change pvar
      quietly rolling, window(12) clear : pvar mag0 mag1 car0 car1 col0 col1 vehicle ka re fd , lags(1/1)
      
      // collect the variable(s) you need from the frame var into frame pvar
      frlink 1:1 start , frame(var)
      frget your_variable_of_choice, from(var)
      
      // now you can create the graph with both parameters


      Thank you warmly for your time and consideration. Indeed, rolling windows overwrite the data, creating a new dataset.

      Perhaps it was me not being clear in #1. If so, I apologize for that!


      I have two types of VARs to run separately from each other. One is a basic rolling windows vector autoregression VAR, the var command, and the other is a rolling windows panel data vector autoregression VAR, the pvar command. I provided the data for the first basic rolling window vector autoregression VAR in order not to spam the forum along with the codes for the two types of models, thinking eventually wrongly that I should be able to get what I want from there. Similarly, for the rolling Windows panel data vector autoregression var, use the pvar command. I can provide data for the rolling Windows panel data vector autoregression VAR with the pvar command, should that be necessary.


      I didn't find any e() stored for the variance and covariance in the help file after the rolling windows, nor could I figure out how to derive the variance and covariance parameters and then graph them.

      To keep it short and clear, what I would like is something like the following two graphs I found in a research paper, which explore the credible intervals of each of the covariance and variance parameters. Some authors have used Monte Carlo burns in order to get similar results. I am happy to accept that approach as long as I can get results.


      Thank you again for any help you could provide

      Best,

      Mario

      Click image for larger version

Name:	examples_notebooks_generated_statespace_tvpvar_mcmc_cfa_37_0.png
Views:	1
Size:	33.5 KB
ID:	1715681



      Click image for larger version

Name:	examples_notebooks_generated_statespace_tvpvar_mcmc_cfa_38_0.png
Views:	1
Size:	61.6 KB
ID:	1715682

      Last edited by Mario Ferri; 31 May 2023, 13:10.

      Comment


      • #4
        Originally posted by Mario Ferri View Post



        Thank you warmly for your time and consideration. Indeed, rolling windows overwrite the data, creating a new dataset.

        Perhaps it was me not being clear in #1. If so, I apologize for that!


        I have two types of VARs to run separately from each other. One is a basic rolling windows vector autoregression VAR, the var command, and the other is a rolling windows panel data vector autoregression VAR, the pvar command. I provided the data for the first basic rolling window vector autoregression VAR in order not to spam the forum along with the codes for the two types of models, thinking eventually wrongly that I should be able to get what I want from there. Similarly, for the rolling Windows panel data vector autoregression var, use the pvar command. I can provide data for the rolling Windows panel data vector autoregression VAR with the pvar command, should that be necessary.


        I didn't find any e() stored for the variance and covariance in the help file after the rolling windows, nor could I figure out how to derive the variance and covariance parameters and then graph them.

        To keep it short and clear, what I would like is something like the following two graphs I found in a research paper, which explore the credible intervals of each of the covariance and variance parameters. Some authors have used Monte Carlo burns in order to get similar results. I am happy to accept that approach as long as I can get results.


        Thank you again for any help you could provide

        Best,

        Mario

        [ATTACH=CONFIG]n1715681[/ATTACH]


        [ATTACH=CONFIG]n1715682[/ATTACH]
        I found the
        Code:
         designplot
        command written by Nick Cox, but did not get or manage to produce the desired graph. I would be grateful for any help you could provide.

        Best,

        Mario

        Comment


        • #5
          Thanks for the mention, but I can't see any connection whatsoever between designplot (Stata Journal) and what little I understand here.

          Comment


          • #6
            For the record, I found out that this can be plotted with state space models. Some programming is needed, though!

            Comment

            Working...
            X